<?php

//------------------------------------------------------------------
// File: Team.class.php
// Author: Bryan Frost
// Date Created: 2010-03-25
//
// Team Management
//------------------------------------------------------------------

// Team object containing id, and players.
class TeamData
{
	private $teamId;
	private $conditionalResult;
	private $playerCollection;

	protected function setTeamId($teamId)						{ $this->teamId = $teamId; }
	public function GetTeamId()									{ return $this->teamId; }
	
	protected function setConditionalResult($conditionalResult)	{ $this->conditionalResult = $conditionalResult; }
	public function GetConditionalResult()						{ return $this->conditionalResult; }
	
	protected function setPlayerCollection($playerCollection)	{ $this->playerCollection = $playerCollection; }
	public function GetPlayerCollection()						{ return $this->playerCollection; }	
}

// Core Team logic.
class Team extends TeamData
{
	// Get Team based on TeamID.
	public function GetTeam($teamId)
	{
		$t = new TeamData();
		
		$query  = "SELECT PlayerID, FirstName, LastName FROM Teams ";
		$query .= "INNER JOIN Players USING (PlayerID) ";
		$query .= "WHERE TeamID = $teamId";
		$result = GetQueryResult($query);
		
		$playerCollection = array();
		
		// Populate teamate array with teamate.
		while($row = mysqli_fetch_array($result))
		{
			$playerCollection[] = Player::GetPlayerBaseData($row['PlayerID'], $row['FirstName'], $row['LastName']);
		}
		
		$t->setTeamId($teamId);
		$t->setPlayerCollection($playerCollection);
		
		return $t;
	}
	
	// Update Team object with result.
	// TODO: Refactor
	public function AddResultToTeam($team, $result)
	{
		$team->setConditionalResult($result);
		return $team;
	}
	
}

?>